Release 10.1A: OpenEdge Data Management:
SQL Reference
LOCK TABLE
Explicitly locks one or more specified tables for shared or exclusive access.
Syntax
table_nameThe table in the database that you want to lock explicitly. You can specify one table or a comma-separated list of tables.
SHARE MODEAllows all transactions to read the tables. Prohibits all other transactions from modifying the tables. After you acquire an explicit lock on a table in
SHAREMODE, anySELECTstatements in your transaction can read rows and do not implicitly acquire individual record locks. AnyINSERT,UPDATE, andDELETEstatements do acquire record locks.EXCLUSIVE MODEAllows the current transaction to read and modify the tables, and prohibits any other transactions from reading or modifying the tables. After you acquire an explicit lock on a table in
ExamplesEXCLUSIVEMODE, you canSELECT,INSERT,UPDATE, andDELETErows, and your transaction does not implicitly acquire individual record locks for these operations.Unless another transaction holds an
EXCLUSIVElock on theteratabandmegatabtables, theSHARE MODEexample explicitly locks the tables. The shared lock allows all transactions to read the tables. Only the current transaction can modify the tables, as shown in the following example:
Unless another transaction holds a lock on the
teratabtable, theEXCLUSIVE MODEexample locks theteratabtable for exclusive use by the current transaction. No other transactions can read or modify theteratabtable, as shown in the following example:
Without a table lock, the first
SELECTstatement in this example could exceed the limits of the record lock table, while theLOCK TABLEstatement prevents the subsequentSELECTstatement from consuming the record lock table:
Notes
- The
LOCK TABLEstatement might encounter a locking conflict with another transaction.- The
SHARE MODEoption detects a locking conflict if another transaction:- The
EXCLUSIVEMODEoption detects a locking conflict if another transaction:- When there is a locking conflict, the transaction is suspended and the database returns an error. You might configure the time at which the transaction is suspended. The default is five seconds.
- You can use explicit table locking to improve the performance of a single transaction, at the cost of decreasing the concurrency of the system and potentially blocking other transactions. It is more efficient to lock a table explicitly if you know that the transaction will be updating a substantial part of a table. You gain efficiency by decreasing the overhead of the implicit locking mechanism, and by decreasing any potential wait time for acquiring individual record locks on the table.
- You can use explicit table locking to minimize potential deadlocks in situations where a transaction is modifying a substantial part of a table. Before making a choice between explicit or implicit locking, compare the benefits of table locking with the disadvantages of losing concurrency.
Note: See the SET TRANSACTION ISOLATION LEVEL statement for information on isolation levels and the inconsistencies allowed by each.- The database releases explicit and implicit locks only when the transaction ends with a
COMMITorROLLBACKoperation.Authorization
Must have
DBAprivilege orSELECTprivilege on the table.Related statements
COMMIT, ROLLBACK, SET TRANSACTION ISOLATION LEVEL
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |